<template>
  <div class="produceDetail-container">
    <img class="menu-icon" src="../../assets/images/menu.png" alt="" @click="dialogVisible = true" />

    <div class="content">
      <ElCard>
        <div>
          <div class="main flex">
            <ElRow style="width: 100%">
              <ElCol :xl="24" :lg="24" :xs="24" class="process" style="margin-bottom: 20px">
                <div class="el-descriptions">
                  <ElRow :gutter="8">
                    <ElCol :span="24">
                      <div class="el-descriptions__cell">
                        <span class="el-descriptions__label">任务单生产内容列表</span>
                      </div>
                    </ElCol>
                    <ElCol :span="24">
                      <div class="card-yq" v-loading="loading">
                        <el-row class="card-yq-title" style="width: 100%; justify-content: space-between">
                          <el-col :span="6"><div class="grid-title">产品名称</div></el-col>
                          <el-col :span="4"><div class="grid-title">客户需求数量</div></el-col>
                          <el-col :span="4"><div class="grid-title">工单数量</div></el-col>
                          <el-col :span="4"><div class="grid-title">已完全生产数量</div></el-col>
                          <el-col :span="6"><div class="grid-title">需求时间</div></el-col>
                          <!-- <el-col :span="8"
                            ><div class="grid-title">
                              工序详情 注:(需求数量/ <span style="color: #65baf2">已生产数量/</span>
                              <span style="color: #768e20">本周生产数量/</span>不良数量)
                            </div></el-col
                          > -->
                        </el-row>
                        <div class="card-scroll">
                          <vue3-seamless-scroll
                            v-model="isScroll"
                            v-if="orderList.length"
                            :list="orderList"
                            class="scroll">
                            <el-row
                              v-for="(item, index) in orderList"
                              :key="index"
                              style="width: 100%; justify-content: space-between">
                              <el-col :span="6">
                                <div class="grid-title grid-title-center">{{ item.productName }}</div>
                              </el-col>
                              <el-col :span="4">
                                <div class="grid-title grid-title-center">{{ item.demandCount }}</div>
                              </el-col>
                              <el-col :span="4">
                                <div class="grid-title grid-title-center">{{ item.quantity }}</div>
                              </el-col>
                              <el-col :span="4">
                                <div class="grid-title grid-title-center">{{ item.quantityProduced }}</div>
                              </el-col>
                              <el-col :span="6">
                                <div class="grid-title grid-title-center">{{ item.planEndDate }}</div>
                              </el-col>
                              <!-- <el-col :span="8">
                                <div class="grid-title grid-title-center">{{ item.address }}</div>
                              </el-col> -->
                            </el-row>
                          </vue3-seamless-scroll>

                          <BiEmpty v-else />
                        </div>
                      </div>
                    </ElCol>
                  </ElRow>
                </div>
              </ElCol>
              <ElCol :xl="24" :lg="24" :xs="24" class="process" style="margin-bottom: 20px">
                <div class="el-descriptions" v-loading="iframeLoading">
                  <div class="text"> ！请谨慎切换甘特图模式，较占内存</div>
                  <iframe
                    :src="`${iframeUrl}${params.workorderName}`"
                    frameborder="0"
                    style="width: 100%; height: 600px"></iframe>
                </div>
              </ElCol>
              <ElCol :xl="24" :lg="24" :xs="24" class="process">
                <ElRow :gutter="16">
                  <ElCol :xl="24" :lg="24" :xs="24" class="process">
                    <div class="el-descriptions" style="height: 260px">
                      <div class="el-descriptions__cell">
                        <span class="el-descriptions__label"> 单件产品清单</span>
                      </div>
                      <el-button type="primary" v-for="item in 2" :key="item">D240628-1- {{ item + 2 }}</el-button>
                    </div>
                  </ElCol>
                </ElRow>
              </ElCol>
            </ElRow>
          </div>
        </div>
      </ElCard>
    </div>

    <!-- 任务单弹窗 -->
    <el-dialog v-model="dialogVisible" title="任务单列表" width="380">
      <div class="modal-content">
        <div class="nav">
          <span
            v-for="(item, i) in TaskTypeList"
            :key="i"
            :name="item.value"
            :class="params.type == item.value ? 'active' : ''"
            @click="handelTask(item.value)"
            >{{ item.label }}</span
          >
        </div>

        <div class="search flex_column_center">
          <div class="search-card" style="width: 100%">
            <el-input v-model="searchValue" placeholder="请输入任务单号或产品编号" :suffix-icon="Search" />
          </div>
        </div>

        <el-divider />

        <div class="task-order" style="height: 460px" v-loading="modalLoading">
          <div
            class="flex_sb"
            v-for="(item, i) in allTaskList"
            :key="i"
            style="margin-bottom: 8px"
            @click="handelTaskDetail(item)">
            <span class="code">任务单号：{{ item.workOrderName }} </span>
            <span class="date"> 交货日期：{{ item.requestDate || '--' }}</span>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue';
import { Search } from '@element-plus/icons-vue';
import { getAllMainWorkOrder, getStatisticList } from '../../api/taskBi';

defineOptions({
  name: 'TaskDetail',
});

// const props = defineProps({
//   type: {
//     type: Number,
//     default: 2, //统计类型:1-代表本周;2-代表本月;3-代表本年;4-代表自定义时间
//   },
//   timeRange: {
//     type: Object,
//     default: {
//       startTime: '',
//       endTime: '',
//     }, //时间区间
//   },
// });

const loading = ref(false);
const modalLoading = ref(false);
const iframeLoading = ref(false);
const seamlessScroll = ref();

const iframeUrl = ref('');

const dialogVisible = ref(false);

// 任务类型
const TaskTypeList = [
  { value: 1, label: '全部' },
  { value: 2, label: '已完成' },
  { value: 3, label: '正在进行中' },
  { value: 4, label: '已下发' },
];

const searchValue = ref('');
const allTaskList = ref<any>([]);
const orderList = ref<any>([]);
const isScroll = ref(false)

const params = reactive({
  type: 1, //类型：1-全部；2-已完成；3-进行中；4-已下发
  ifNeed: 'Y', //是否展示需求数量：Y-是；N-否
  ifProduce: 'Y', //是否展示已生产数量：Y-是；N-否
  ifWeekProduce: 'Y', //是否展示本周生产数量：Y-是；N-否
  ifBad: 'Y', //是否展示不良数量：Y-是；N-否
  workorderId: '289', //任务单ID 必填
  workorderName: '',
});

onMounted(() => {
  const myVar: any = import.meta.env;
  const httpUrl = myVar.MODE == 'production' ? 'http://192.168.1.101:5138/' : 'http://dhtmlx.ldyxx.com/';
  iframeUrl.value = `${httpUrl}dxhtml/samples/view/index.html?code=`;
  _getAllMainWorkOrder(true);
});

const getPageData = async () => {};
// 选择任务类型
const handelTask = (value: number) => {
  params.type = value;
  modalLoading.value = true;

  _getAllMainWorkOrder();
};
// 获取任务详情
const handelTaskDetail = ({ workOrderId, workOrderName }: any) => {
  dialogVisible.value = false;
  params.workorderId = workOrderId;
  params.workorderName = workOrderName;
  _getOnceStatisticList();
};
// 打开菜单弹窗

// 获取全部任务
const _getAllMainWorkOrder = (isFirst = false) => {
  getAllMainWorkOrder({
    type: params.type,
    workorderId: searchValue.value,
  }).then(async (_res) => {
    allTaskList.value = _res.data;
    setTimeout(() => {
      modalLoading.value = false;
    }, 500);

    if (isFirst) {
      params.workorderId = await _res.data[0].workOrderId;
      params.workorderName = await _res.data[0].workOrderName;
      _getOnceStatisticList();
    }
  });
};
// 任务单生产内容列表
const _getOnceStatisticList = () => {
  loading.value = true;

  getStatisticList({
    type: params.type,
    ifNeed: params.ifNeed,
    ifProduce: params.ifProduce,
    ifWeekProduce: params.ifWeekProduce,
    ifBad: params.ifBad,
    workorderId: params.workorderId,
  }).then((_res) => {
    orderList.value = _res.data[0].orderList;
    setTimeout(() => {
      loading.value = false;
    }, 500);
  });
};

defineExpose({
  getPageData,
});
</script>

<style lang="scss" scoped>
.produceDetail-container {
  position: relative;
  .menu-icon {
    position: fixed;
    top: 110px;
    left: 0px;
    width: 60px;
    height: 60px;
    cursor: pointer;
  }
  .search-card {
    position: relative;
    width: 40%;
    min-height: 40px;
    height: 40px;
    background: #0f0c29;
    background: linear-gradient(to right, #24243e, #302b63, #0f0c29);
    border: 3px solid #101f58;
    border-radius: 4px;
    // margin-bottom: 20px;
    &::before {
      position: absolute;
      top: -3px;
      bottom: -3px;
      left: 30px;
      z-index: 0;
      width: calc(100% - 60px);
      pointer-events: none;
      content: '';
      border-top: 3px solid #101f58;
      border-bottom: 3px solid #101f58;
    }

    &::after {
      position: absolute;
      top: 30px;
      right: -3px;
      left: -3px;
      z-index: 0;
      height: calc(100% - 60px);
      pointer-events: none;
      content: '';
      border-right: 3px solid #101f58;
      border-left: 3px solid #101f58;
    }

    :deep() {
      .el-input {
        width: 100% !important;
        height: 41px;
        background: transparent;
      }

      .el-input__wrapper {
        background-color: transparent;
        border: 1px solid transparent !important;
        box-shadow: none !important;
      }

      .el-input__inner {
        color: #fff;
      }
    }
  }

  .data-screen-card {
    // position: relative;
    width: 100%;
    min-height: 160px;
    margin-bottom: 20px;
    margin-top: 6px;
    // padding: var(--el-padding);
    // border: 3px solid #01ffff;
    border-radius: 5px;
    box-shadow: 0px 0px 6px rgba(195, 211, 222, 0.501960784313725);
    background: #011320;

    display: flex;
    flex-direction: column;

    .card-title {
      padding: 16px;
      padding-bottom: 0px;
      color: #fff;

      span {
        display: inline-block;
        text-align: left;
        height: 20px;
        padding-left: 10px;
        line-height: 20px;
        text-align: left;
        border-left: 3px solid #01ffff;
        width: 140px;
        white-space: nowrap;
        /* 确保文本在一行内显示 */
        overflow: hidden;
        /* 隐藏溢出的内容 */
        text-overflow: ellipsis;
        /* 使用省略号表示文本溢出 */
      }
    }

    .card-content {
      // flex: 1;
      /* 占满剩余空间 */

      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      overflow: hidden;
    }

    .card-yq {
      display: flex;
      flex-direction: column;
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      padding: 0 10px;
      .card-yq-title {
        height: 42px;
        background-image: url('../assets/images/u246.svg'); /* 替换为你的 SVG 文件路径 */
        background-repeat: repeat; /* 实现平铺效果 */
      }
    }

    .grid-title {
      // height: 42px;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      line-height: 20px;
      font-size: 12px;
      // height: 100%;
    }
    .grid-title.grid-title-center {
      color: #f1f2f6;
      font-size: 12px;
    }
  }

  .modal-content {
    :deep() {
      .el-divider--horizontal {
        margin: 14px 0;
      }
    }

    .nav {
      display: flex;
      margin-bottom: 12px;
      span {
        background: rgba(64, 158, 255, 0.4);
        color: #ffffff;
        display: inline-block;
        font-size: 12px;
        padding: 8px 15px;
        text-align: center;
        border-radius: 2px;
        cursor: pointer;
        &.active {
          background: rgba(64, 158, 255, 1);
        }
        &:hover {
          background: rgba(64, 158, 255, 1);
        }

        margin-right: 4px;
        &:last-child {
          margin-right: 0px;
        }
      }
    }

    .task-order {
      box-shadow: 0px 0px 6px rgba(195, 211, 222, 0.5019607843);
      padding: 12px;
      overflow-y: auto;
      color: #fff;
      .flex_sb {
        cursor: pointer;
      }
      .date {
        font-size: 12px;
        color: #d3d3d3;
      }
    }
  }
}

.dot {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #fff;
  border: 1px solid #50a3f8;
  text-align: center;
  line-height: 20px;
  color: #409eff;
}

.content {
  :deep() {
    .el-card {
      background-color: transparent !important;
      border: none !important;
    }

    .el-descriptions__body {
      background-color: transparent !important;
    }

    .el-descriptions {
      border: none;
      box-shadow: 0px 0px 6px rgba(195, 211, 222, 0.501960784313725);
      padding: 12px;
      // height: 205px;
      overflow-y: hidden;
      .text{
        float: right;
        margin-bottom: 12px;
        font-size: 12px;
        color: #aaaaaa;
      }
    }

    .el-descriptions__title {
      color: #409eff;
    }

    .el-descriptions__label {
      color: #fff;
      display: inline-block;
      // width: 80px;
      text-align: left;
    }

    .el-timeline-item__dot {
      left: -6px;
    }
  }

  .card-header {
    color: #fff;
  }

  .process {
    .el-descriptions__content {
      color: #fff;
      overflow: hidden;
      max-height: 40px;
      max-width: 160px;
      line-height: 22px;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }

  .use {
    .el-descriptions__content {
      flex: 1;
      display: flex;
      justify-content: space-between;
      line-height: 22px;

      color: #fff;
      // overflow: hidden;
      // max-height: 40px;

      &.black {
        color: #a0a2a4;
      }

      .value {
        overflow-wrap: break-word; /* 允许在单词内断行 */
        word-break: break-word; /* 防止将单词拆分到下一行 */
        max-width: 130px;
        // min-width: 70px;
        // text-overflow: ellipsis;
        // display: -webkit-box;
        // -webkit-line-clamp: 2;
        // -webkit-box-orient: vertical;
      }
      .link {
        display: inline-block;
        max-width: 56px;
        min-width: 30px;
        height: 23px;
        line-height: 23px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }

  .order {
    .cell {
      .title {
        color: #fff;
        margin-bottom: 8px;
      }
      .drop {
        color: #409eff;
      }
    }

    .el-descriptions {
      display: flex;
      flex-direction: column;
      .order_content {
        flex: 1;
        overflow-y: auto;
      }
    }
  }

  img {
    // transform: rotate(90deg)  translate(calc( 100vh / 2 - 100vw / 2) , calc(100vh / 2 - 100vw / 2));
    display: block;
    max-width: 100%;
    height: 100px;
    cursor: pointer;
    transform: rotate(90de);
  }
}

.el-descriptions__cell {
  padding-bottom: 12px;
  display: flex;

  &.not {
    padding-bottom: 0px;
  }

  .material_list {
    width: 100%;

    .material_cell {
      padding: 4px 8px;
      border-bottom: 1px dashed #8f959a;

      .flex {
        span {
          font-size: 12px;
          margin: 2px;
          color: #fff;

          &:last-child {
            margin-right: 0px;
          }
        }
      }
    }
  }
}

.el-descriptions__header {
  margin-bottom: 16px;
  color: #409eff;
  font-size: 16px;
  font-weight: bold;
}

.el-descriptions__label {
  font-size: 14px;
  font-weight: normal;
  line-height: 23px;
  &.black {
    color: #a0a2a4;
  }

  &.auto {
    width: auto;
  }
}

// 初始化卡片
.init-card {
  :deep() {
    .card-header {
      color: #000000;
    }
    .el-card {
      background-color: #fff !important;
      margin-bottom: 20px;
      &:last-child {
        margin-bottom: 0px;
      }
    }
  }
}

.card-content {
  width: 100%;
  // height: 200px;
}

.card-scroll {
  overflow: hidden;
  flex: 1;
  .scroll {
    width: 100%;
    max-height: 400px;
    overflow-y: auto;
  }
}
</style>
